//
//  SwiftUIView_Transition.swift
//  SwiftUIPractice
//
//  Created by 下午雨停了,风也没了   (external - Project) on 2024/9/16.
//

import SwiftUI

struct SwiftUIView_Transition: View {
    
    @State var showView = false
    
    var body: some View {
        
        ZStack(alignment: .bottom) {
            
            VStack {
                Button("这是一个按钮") {  
                    showView.toggle()
                }
                Spacer()
            }
            
            if showView {
                
                RoundedRectangle(cornerRadius: 30).frame(height: 400)
                    //.opacity(showView ? 1 : 0)  这个东西就不要了
                
                    //.transition(.slide) //从左往右的移动效果
                    //.transition(.move(edge: .bottom))  //从下面进, 然后从下面出去
                    
                
                // 使用transition然后要实现动画效果, 需要这样使用
                    //.transition(AnyTransition.opacity.animation(.easeInOut))
                    //.transition(AnyTransition.scale.animation(.easeInOut))

                //控制它入场和出场的方式
                    .transition(
                        .asymmetric(
                            insertion: .move(edge: .leading),
                            //removal: .move(edge: .bottom)
                            removal: AnyTransition.opacity.animation(.easeInOut)
                        ))
                
                    //.animation(.easeInOut)
                    .animation(.spring)  //这个就像是 从下往上的弹框动画了
            }
        }
        .ignoresSafeArea(.all, edges: .bottom)
        
    }
}

#Preview {
    SwiftUIView_Transition()
}
